﻿using Adp;
using Microsoft.AspNetCore.Mvc;
using Yqd.Models;
using System.Linq;
using Adp.Common;
using Yqd.Controllers.Filter;

namespace Yqd.Controllers
{
    [Area("Yqd")]
    public class WxStreetController : Controller
    {
        YqdContext ctx;

        public WxStreetController(YqdContext ctx)
        {
            this.ctx = ctx;
        }

        [User]
        public IActionResult GetList()
        {
            return this.ToJson(new
            {
                success = true,
                data = ctx.Yqd_Street.OrderByDescending(it => it.Tactic).Select(it =>
                 new
                 {
                     label = it.Name,
                     value = it.StreetID
                 })
            });
        }

        [User]
        public IActionResult GetCommunityList()
        {
            var StreetID = Form.GetInt("StreetID");
            var r = ctx.Yqd_Community.AsQueryable();
            if (StreetID > 0) r = r.Where(it => it.StreetID == StreetID);
            return this.ToJson(new
            {
                success = true,
                data = r.OrderByDescending(it => it.Tactic).Select(it => new
                {
                    label = it.Name,
                    value = it.CommunityID
                })
            });
        }
    }
}
